﻿using BankAccountNS;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace TestProject1
{


    /// <summary>
    ///这是 BankAccountTest 的测试类，旨在
    ///包含所有 BankAccountTest 单元测试
    ///</summary>
    [TestClass()]
    public class BankAccountTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Debit 的测试
        ///</summary>
        [TestMethod()]
        public void DebitTest()
        {
            BankAccount target = new BankAccount("Mr.Bryan Walton", 11.99);
            double amount = 11.22;
            target.Debit(amount);
            //Assert.Inconclusive("无法验证不返回值的方法。");
            Assert.AreEqual((System.Convert.ToDouble(0.77)), target.Balance, 0.05);
        }

        /// <summary>
        ///Credit 的测试
        ///</summary>
        [TestMethod()]
        public void CreditTest()
        {
            BankAccount target = new BankAccount("Mr.Bryan Walton", 11.99);
            double amount = 11.22;
            target.Credit(amount);
            Assert.Inconclusive("无法验证不返回值的方法。");
        }

        /// <summary>
        ///FreezeAccount 的测试
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Bank.dll")]
        public void FreezeAccountTest()
        {
            BankAccount_Accessor target = new BankAccount_Accessor("Mr.Bryan Walton", 11.99); // TODO: Initialize to an appropriate value
            target.FreezeAccount();
            // Assert.Inconclusive("A method that does not return a value cannot be verified.");       
            bool creditAccount = false; // False means account could be credited: Fail test.     // Try to credit account    
            try
            {
                target.Credit(15.00);
            }
            catch (System.Exception)
            {
                // Threw exception.FreezeAccount worked correctly: Pass test.        
                creditAccount = true;
            }    // Assert fails if 'creditAccount' condition is false.Fail test.    
            Assert.IsTrue(creditAccount, "Was able to credit account.");
        }
    }
}
